<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:component xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">



	<rich:popupPanel id="popupRicercaProdotti" width="500" height="500"
		domElementAttachment="parent">
		<f:facet name="header">Ricerca Prodotti</f:facet>
		<f:facet name="controls">

			<h:outputLink value="#"
				style="font-size:large; color:black; textdecoration:none;"
				onclick="#{rich:component('popupRicercaProdotti')}.hide();return false;">X
			</h:outputLink>

		</f:facet>

		<rich:extendedDataTable id="tabellaRicercaProdotti"
			value="#{selectBean.prodottiAttivi}" var="prodotto"
			selection="#{selectBean.selection}"
			selectionMode="#{selectBean.selectionMode}" rows="10" >

			<a4j:ajax event="selectionchange"
				listener="#{selectBean.tableListener}" />

			<rich:column width="100px">
				<f:facet name="header">Codice Prodotto</f:facet>
				<h:outputText value="#{prodotto.codiceProdotto}" />
			</rich:column>



			<rich:column width="100px">
				<f:facet name="header">Descrizione</f:facet>
				<h:outputText value="#{prodotto.descrizione}" />
			</rich:column>
			
			
			<rich:column width="150px" >
				<f:facet name="header">
					<h:panelGroup>
						<h:outputText value="Categoria" />
						
						<ui:remove>
						<rich:select 	id="selezionaCategoria11" defaultLabel="Seleziona Categoria" converter="#{categoriaConverter}"
										 	listWidth="120px" styleClass="mySelect"
											value="#{prodotto.categoria}"  >
					   			<f:selectItems value="#{selectBean.categorieSelezionate}"   />   
					   			<a4j:ajax render="tabellaRicercaProdotti" execute="@this"
								event="change" />             			
							</rich:select>
						</ui:remove>
					</h:panelGroup>
				</f:facet>
				<h:outputText value="#{prodotto.categoria.nome}" />
			</rich:column>
			

			<rich:column width="100px"
				filterValue="#{genericFilterBean.provanienzaProdotto}"
				filterExpression="#{fn:containsIgnoreCase(prodotto.provenienza,genericFilterBean.provanienzaProdotto)}"
				filterType="custom" style="text-align:center;">

				<f:facet name="header">
					<h:panelGroup>
						<h:outputText value="Provenienza" />


						<h:selectOneMenu value="#{genericFilterBean.provanienzaProdotto}"
							label="">
							<f:selectItem itemValue="" />
							<f:selectItem itemValue="locale" />
							<f:selectItem itemValue="CurdBee" />
							<a4j:ajax render="tabellaRicercaProdotti" execute="@this"
								event="change" />
						</h:selectOneMenu>



					</h:panelGroup>
				</f:facet>


				<h:graphicImage value="#{pathImmagini.pathImmagineGefoBlack}"
					rendered="#{prodotto.provenienza == 'locale'}" />
				<h:graphicImage value="#{pathImmagini.pathImmagineCurdBee}"
					rendered="#{prodotto.provenienza == 'CurdBee'}" />

			</rich:column>
			<f:facet name="footer">
				<rich:dataScroller />
			</f:facet>

		</rich:extendedDataTable>

		<br /><br />
		

		<a4j:commandButton value="Aggiungi Prodotto a fattura"
					action="#{tabsBean.addProdottoALineaFattura(selectBean.prodottoSelezionato,tab.name)}"
					oncomplete="#{rich:component('popupRicercaProdotti')}.hide();return false;"
					render="tabellaLineeFattura" execute="@this" rendered="#{fn:containsIgnoreCase(tab.name,'Fattura')}"/>

		<a4j:commandButton value="Aggiungi Prodotto a ordine"
					action="#{tabsBean.addProdottoALineaOrdine(selectBean.prodottoSelezionato,nomeTab)}"
					oncomplete="#{rich:component('popupRicercaProdotti')}.hide();return false;"
					render="tabellaLineeOrdine" execute="@this" rendered="#{fn:containsIgnoreCase(tab.name,'Ordine')}"/>
					
	</rich:popupPanel>
</ui:component>
